home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / fichier.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  3KB  |  96 lines

  1. /****************************************************************/
  2. /*                                                              */
  3. /*     fichier      : fichier.c                                 */
  4. /*     projet       : Amiglobe                                  */
  5. /*     date création: mars 1994                                 */
  6. /*     commentaire  : fonctions d'accès aux fichiers            */
  7. /*     révision     : $VER: fichier.c 0.002 (04 Oct 1994)       */
  8. /*     copyright    : © 1994 Olivier Collard                    */
  9. /*     $HISTORY:                                                */
  10. /*                                                              */
  11. /*              mars 1994 : 0.01 : version initiale, projet     */
  12. /*                                 Shannon-Fano                 */
  13. /*              4 oct 1994 : 0.002 : version initiale, projet   */
  14. /*                                  Amiglobe                    */
  15. /*                                                              */
  16. /****************************************************************/
  17.  
  18.  
  19.  
  20.  
  21. /* includes spécifiques pour Amiga: */
  22. #include <dos/dosasl.h>   /* gestion des jokers */
  23. #include <clib/dos_protos.h> /* gestion des jokers */
  24.  
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28.  
  29. #include "fichier.h"
  30.  
  31. /* -------------------------- ouvrir_nouveau_fichier ---------------------------
  32.  
  33.  Comment: a chaque appel, donne un pointeur sur un fichier
  34.           correspondant à nom
  35.           si nom change, reprise depuis le début
  36.  
  37. */
  38.  
  39. char  *
  40. ouvrir_nouveau_fichier(char * nom)
  41. // fonction specifique a chaque systeme (noms)
  42. {
  43.     static struct AnchorPath __aligned * anchor=NULL;
  44.     // spécifique AmigaDOS: contient le 'pattern' à mettre en
  45.     // correspondance avec les noms de fichiers
  46.     // vaut NULL au premier appel
  47.     /*char nom_fichier [32];*/
  48.     /*FILE * fichier=NULL;  */
  49.     static char * pattern="";
  50.     // pattern de recherche; s'il est different de nom, 
  51.     // il faut recommencer la recherche
  52.     if (strcmp(pattern,nom)!=0)
  53.     {
  54.         anchor=NULL;
  55.         free(pattern);
  56.         pattern=strdup(nom);
  57.     }
  58.     if (anchor==NULL)
  59.     {
  60.         // initialisation de anchor lors du premier appel
  61.         anchor = (struct AnchorPath __aligned *)malloc
  62.                 (sizeof(struct AnchorPath ));
  63.         memset(anchor,0,sizeof(struct AnchorPath));
  64.  
  65.         // dans le cas du premier appel
  66.         if (MatchFirst(pattern,anchor)!=0)
  67.         {
  68.             /*printf("Erreur dans la recherche du fichier\n");*/
  69.             return NULL;
  70.         }
  71.         /*printf("trouve:%s\n",(anchor->ap_Info).fib_FileName);*/
  72.         // recherche d'un fichier
  73.         return (anchor->ap_Info).fib_FileName;
  74.     }
  75.     else
  76.     {
  77.         // recherche d'autres fichiers
  78.         if (MatchNext(anchor)!=0)
  79.         {
  80.             /*printf("pas d'autres fichiers trouves\n");*/
  81.             // si ne trouve plus d'autres fichiers,
  82.             // positions_nom[i] vaut "" et positions[i] vaut
  83.             // la position de fin du dernier fichier
  84.             MatchEnd(anchor);
  85.             // fermeture de anchor
  86.             return NULL;
  87.         }
  88.         else
  89.         {
  90.             /*printf("trouve:%s\n",(anchor->ap_Info).fib_FileName);*/
  91.             return (anchor->ap_Info).fib_FileName;
  92.         }
  93.     }
  94. }
  95.  
  96.